<?php

namespace app\teacher\controller\v1;

use app\api\model\Course as CourseModel;
use app\api\service\CourseOrderService;
use app\common\controller\BaseController;
use think\Controller;
use think\Request;
use app\teacher\model\CourseOrder as CourseOrderModel;

class Order extends BaseController
{
    /**
     * 我的订单
     */
    public function index()
    {
        $status = $this->request->get('status');
        $size = $this->request->get('size');
        $orders = CourseOrderModel::getUserOrders($this->teacherId, $status, $size);
        $orders->total() ? $this->success('', [
            'orders' => $orders->items(),
            'total' => $orders->total()
        ]) : $this->notFoundData();
    }

    /**
     * 订单详情
     */
    public function read()
    {
        $courseOrderId = $this->notEmpty('course_order_id');
        $order = CourseOrderModel::getByOrderId($courseOrderId);
        if (!$order) {
            $this->errorMsg(13001);
        }
        //课表
        $order['course_count'] = CourseModel::getDateCount($courseOrderId);
        $this->success('', compact('order'));
    }
}
